package a3;

public class Game {

	boolean EnableGui;
	static int EpisodeToPlay = 10000;
	static int MaximumTurns = 1000;
	static int BoardSize = 11;
	static int initQ = 15;
	static float Alpha = 0.5f;
	static float Gamma = 0.5f;
	static float Epsilon = 0.2f;

	public static void main( String[] args ) {
		int totalconverge = 0;
		Game game = new Game(false, EpisodeToPlay, MaximumTurns, BoardSize);
		float avgturns = game.playEpisodes();
		totalconverge += avgturns;
		System.out.println("Average converge: "+ (float) ((float)totalconverge/100f));
	}

	public Game(boolean enableGui, int gamesamount, int maxturns, int boardSize) {
		EnableGui = enableGui;
		EpisodeToPlay = gamesamount;
		MaximumTurns = maxturns;
		BoardSize = boardSize;
	}

	public float playEpisodes() {
		int totalturns = 0;
		Gui gui = new Gui(EnableGui);
		
		Environment env = new Environment(MaximumTurns, BoardSize, Alpha, Gamma, Epsilon, initQ);//
		env.spawnPredator(new Location(0,0), "miniMax");
		//env.spawnPredator(new Location(10,0), "Q");
		env.spawnPrey(new Location(5,5), "miniMax");
		int wins = 0;
		for(int episode = 0; episode < EpisodeToPlay; episode++) {
			if(episode== 9000) {
				gui = new Gui(true);
				gui.setEnvironment(env);
				float rewardperturn = env.playGame(gui);
				
			}
			float rewardperturn = env.playGame(gui);
			if(rewardperturn > 0)
				wins++;			
			env.reset();
			float averagewins = (float)wins/(float)(episode+1);
			System.out.println(rewardperturn + "\t qsize: " + env.getPredators().get(0).miniMax.Q.size());
			//System.out.println(rewardperturn);
		}
		
		return 0f;
	}
}
